﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingsPanel : MonoBehaviour
{
    public static SettingsPanel Instance;

    public Button Button_Back;
    public Slider SliderBar_Music;
    public Slider SliderBar_Sound;

    private void Awake()
    {
        Instance = this;
    }

    void Start()
    {
        EventTriggerListener.Get(Button_Back.gameObject, null).onClick = (GameObject go, object data) =>
        {
            this.Close();
        };

        SliderBar_Music.onValueChanged.AddListener((float value) =>
        {
            Debug.Log(value);
            AudioManager.Instance.volume_music = SliderBar_Music.value;
            PlayerPrefs.SetFloat("volume_music", AudioManager.Instance.volume_music);
        });
        SliderBar_Sound.onValueChanged.AddListener((float value) =>
        {
            Debug.Log(value);
            AudioManager.Instance.volume_sound = SliderBar_Sound.value;
            PlayerPrefs.SetFloat("volume_sound", AudioManager.Instance.volume_sound);
        });
    }

    public void Open()
    {
        this.gameObject.SetActive(true);

        
        
        //SliderBar_Music.value = PlayerPrefs.GetFloat("volume_music", 1);

        //SliderBar_Sound.value = PlayerPrefs.GetFloat("volume_sound", 1);
    }

    public void Close()
    {
        this.gameObject.SetActive(false);
    }

}
